﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gpsys.Service;
using System.IO;
using System.Threading;

namespace BankA.Generator
{
    public class MT103Generator : GPSThread
    {
        public bool Stop { get; set; }

        protected override void Run()
        {
            Stop = false;
            string fileName = "[[GUID]].103.txt";
            string folderPath = @"c:\GPS\MsgFromBank";
            string data = @"{0}|CRED|SDVA|120322|IDR|1000000,50|/3734500000|PT. Angin Ribut|Jakarta|/D/523014000990|CENAIDJA|/C/520008000990|BMRIIDJA|/3854300000|CV. Setia Kawan|Bandung|Payment for Invoice SK0123|OUR|/CODTYPTR/001/IFT00|/CLRC/0140016|/FEAB/R|/PTR/LOCAL-LOCAL";
            int counter = 1;

            while (!Stop)
            {
                string newData = string.Format(data, DateTime.Today.ToString("yyMMdd") + counter.ToString().PadLeft(10, '0'));

                string newfileName = fileName.Replace("[[GUID]]", Guid.NewGuid().ToString());

                string filePath = Path.Combine(folderPath, newfileName);

                using (StreamWriter fs = new StreamWriter(filePath))
                {
                    fs.WriteLine(newData);
                }

                counter++;

                if (counter % 50 == 0) Thread.Sleep(1000);
            }
        }
    }
    
}
